<?php $this->load->view('inc/header'); ?>
<?php
			//query cops_group tables where id
				$this->db->where('group_id',$id);
				$this->db->join('membership','membership.member_id=cops_group.owner');
				$this->db->order_by('create_date','desc');
				
				$q_list_cops = $this->db->get('cops_group');
				
				foreach($q_list_cops->result() as $q_query)
				{
					$owner = $q_query->owner;
					$firstname = $q_query->firstname;
					$lastname = $q_query->lastname;
					$nickname = $q_query->nickname;
					$member_display =$q_query->member_display;
					
					$group_id = $q_query->group_id;
					$group_name = $q_query->group_name;
					$description = $q_query->description;
					$create_date = $q_query->create_date;
					
					$logo = $q_query->logo;
				}
?>
  <?php
					//query member count of group.
					$this->db->where('group_id',$q_query->group_id);
					$co = $this->db->get('cops_group_in');
					$member_count = $co->num_rows();
  ?>
<div class="grid_12" style="background-color:#CCCCCC;">
<!--left side-->
<div class="grid_4 alpha">
  <!-- group search -->
  <div class="grid_4 alpha" style="margin-top:10px;">
    <div id="side-panel-top">
    	<div style="padding-left: 22px; padding-top: 7px; font-weight: bold; color:#666666;">Group Search</div>
    </div>
    <div id="side-panel-middle"> dfgdg </div>
    <div id="side-panel-bottom"></div>
  </div> 
	<!-- search -->

   
    <!--Member in Group-->
    <div class="grid_4 alpha" style="margin-top:8px;">
      <div id="side-panel-top">
      	<div style="padding-left: 22px; padding-top:7px; font-weight: bold; color:#0099CC;">Member in Group  (<?=$member_count?>)</div>
      </div>
      <div id="side-panel-middle">
      	<div id="list_members" style="padding-left:3px; position:relative;">
        	<div id="group_details_1" style="position:relative;  width:265px;"><img src="<?=base_url()?>km_resource/cops_group/km_button.png"/>
            	<div id="text" style="position:absolute; top:0px; left:65px;"><?=character_limiter($group_name,30)?><br/><span>owner <?=$firstname?>&nbsp;<?=$lastname?>&nbsp;(<?=$nickname?>)</span></div>
                <div id="spacer_1" style="border-bottom:thin dashed #BEBEBE; position:relative; bottom:10px;">&nbsp;</div>
                <!--display member-->
                <div id="all_member" style="position:relative; left:0px;">
                	<table border=\"0\"  cellspacing=\"1\" cellpadding=\"1\">
                    <tr>
                	<?php
						$initrows=0;
						//query member of group.
						$this->db->join('membership','membership.member_id=cops_group_in.member_id');
						$this->db->where('group_id',$id);
						$q_show_member = $this->db->get('cops_group_in');
						foreach($q_show_member->result() as $q_show_member1)
						{
							$initrows++;
					?>
                    	<td>
                    		<div id="avatar_id" style="position:relative; left:0px; top:0px; padding:5px 10px 0px 0px;">
                            	<?php
									if($q_show_member1->member_display){
								?>
                                	<img src="<?=base_url()?>km_resource/member_display/<?=$q_show_member1->member_display?>" width="48" height="45" alt="<?=$q_show_member1->nickname?>" style="background:#CCCCCC; padding:2px;"/>
                                <?php
								}
								else{
								?>
                                	<img src="<?=base_url()?>km_resource/member_display/null.png" width="48" height="45" alt="<?=$q_show_member1->nickname?>" style="background:#CCCCCC; padding:2px;"/>
                                <?php
								}
								?>
                            </div>
                            <div id="nickname" style="position:relative; top:0px; font-size:10px; width:46px; text-align:center; color:#10548B;"><?=$q_show_member1->nickname?></div>
                    	</td>
                    <?php
						if(($initrows)%4==0)
						{
							echo "</tr>";
						}
					}//end foreach
					?>
                    </table>
                </div>
                <!--close-->
            </div>
		</div>
      </div>
      <div id="side-panel-bottom"></div>
    </div>
    <!--close-->
    
    
     <!-- upload form -->
  <div class="grid_4 alpha" style="margin-top:10px;">
    <div id="side-panel-top">
    	<div style="padding-left: 22px; padding-top: 7px; font-weight: bold; color:#339900;">Upload File</div>
    </div>
    <div id="side-panel-middle">
    <!-- owner && loggedin -->
    <?php
	if($this->session->userdata('is_logged_in')==true){
	?>
        <!-- member in group -->
    <?php
		//check in member_in if in group editor is show
		
		//find member in group
		$this->db->where('group_id',$id);
		$this->db->where('member_id',$this->session->userdata('member_id'));
		$find_m_in = $this->db->get('cops_group_in');
		$n_rows = $find_m_in->num_rows();
		if($n_rows>0 || $owner==$this->session->userdata('member_id')){
	?>
    	<div id="upload">
        	<form method="post" action="<?=base_url()?>cops/do_upload" enctype="multipart/form-data">
            	  <label style="font-size:10px; color:#666666;">Choose File:</label>
            	<div style="margin-bottom:5px;">	
                    <input type="file" name="userfile" size="30" />
                </div>
                  <label style="font-size:10px; color:#666666;">Description:</label>
                <div style="margin-bottom:10px;">
                    <textarea name="description" cols="25" rows="2"></textarea>
                    <input type="hidden" name="group_id" value="<?=$id?>"/>
                </div>   
                <div>
                	<input type="submit" value="upload" />
                </div>    
            </form>
        </div>
          <?php
		  }
		  }	
		  else{
		  ?>
          <div id="msg" style="width:250px;">Please join to this group, To be able to upload the file. </div>
          <?php
		  }
		  ?>
    </div>
    <div id="side-panel-bottom"></div>
  </div> 

	<!-- close upload form -->
    
 </div>
<!--close left side-->


  <div class="grid_8 omega">
  
  <!-- fils_in_group-->
  <div class="grid_8 alpha" style="margin-top:8px;">
    <div id="km-topic">
    <?php
		//count file in group by id
		$this->db->where('group_id',$id);
		$q_d_count = $this->db->get('cops_files');
		$files_count = $q_d_count->num_rows();	//count.
	?>
    	<div style="padding-left: 15px; padding-top: 7px; color:#008040; font-weight: bold; position:relative;">Files in Group (<?=$files_count?>)

        </div>
        
    </div>
    <div id="km-new-middle">
    
    <!-- owner && loggedin -->
    <?php
	if($this->session->userdata('is_logged_in')==true){
	?>
        <!-- member in group -->
    <?php
		//check in member_in if in group editor is show
		
		//find member in group
		$this->db->where('group_id',$id);
		$this->db->where('member_id',$this->session->userdata('member_id'));
		$find_m_in = $this->db->get('cops_group_in');
		$n_rows = $find_m_in->num_rows();
		if($n_rows>0 || $owner==$this->session->userdata('member_id')){
	?>
    
    <!-- display discuss 5 orders -->
    <div id="list_discuss" style="margin-bottom:10px; padding-left:15px;">
       	<?php
			$this->db->join('membership','membership.member_id=cops_files.member_id');
			$this->db->limit(10);
			$this->db->order_by('files_id','desc');
			$this->db->where('group_id',$id);
			$list_files = $this->db->get('cops_files');
			
			foreach($list_files->result() as $l_f_query){
		?>
        	<div id="discuss-<?=$l_f_query->files_id?>" style="margin-top:10px">
            	<div id="wrap_body" style="padding-top:10px">
                
            		<div id="avatar" style="width:48px; float:left; padding:3px; background:#CFCFCF; clear:right;">
                    	<img src="<?=base_url()?>km_resource/member_display/<?=$l_f_query->member_display?>" width="48" height="48" alt="<?=$l_f_query->nickname?>"/>
                    </div>
                    <div id="files_body" style="position:relative; left:5px; width:550px;">
                    	<div id="file_name">
                            File name: <?=$l_f_query->files_name?>

                        </div>
                        <div id="file_type" style="font-size:11px; color:#339933;">File type: <?=$l_f_query->file_type?></div>
                    	<div id="author" style="font-size:11px; color:#333333;">Upload by: <?=$l_f_query->firstname?>&nbsp;<?=$l_f_query->lastname?>&nbsp;(<?=$l_f_query->nickname?>) | <?=$l_f_query->date_upload?></div>
                    	<div id="text" style="font-size:11px; font-weight:bold; color:#CC6600;">Description: <?=$l_f_query->description?></div>
                    </div>
                    <div id="bottom_border" style="border-bottom: thin dashed #CCCCCC; width:575px;">
                <!-- delete files owner-->
                <script>
					function del_discuss(id){
						var discuss_id = id;
						var conf = confirm("Confirm to delete or Cancel ?");
						
						if(conf==true){
							window.location.href="<?=base_url()?>cops/groups/"+<?=$group_id?>+"/delete_discuss/"+discuss_id;
						}
					}
				</script>
                	
                	<div id="bar" style="float:right;">
                            <img src="<?=base_url()?>images/graphic/disk-small-black.png" style="vertical-align:middle;"/><span style="font-size:10px; color:#CC0000;"><a href="<?=site_url()?>/cops/download_files/<?=base64_encode($l_f_query->files_name)?>">download</a></span>
                            <img src="<?=base_url()?>images/graphic/cross-small.png" style="vertical-align:middle;"/><span style="font-size:10px; color:#CC0000;"><a href="javascript:del_discuss(<?=$l_f_query->files_id?>)">delete ?</a></span>
                    </div>
              
                <!-- close delete files owner -->    
                <div id ="clear_both" style="clear:both;"></div>
                    </div>
            	</div>
            </div>
        <?php
		}//end foreach
		?>    
    </div>
    <!-- close display 5 orders-->
    <?php
	}
	else{
	
	?>
    <div id="msg_notice" style="padding-left:15px;">
        	Please join to this group, To be able to download the file.
        </div>
    <?php
	}
	}
	else{
	?>
    <div id="msg_notice" style="padding-left:15px;">
        	Please join to this group, To be able to download the file.
        </div>
    <?php
	}
	?>
        <!-- close member in group -->
        <div id="spacer">&nbsp;</div>
    </div>
    <div id="km-new-bottom"></div>
  </div>
  <!-- close-->
  
</div>
</div>

<div class="clear"></div>
<!--end content1-->
<div class="grid_12" style="background-color:#CCCCCC;">&nbsp;</div>
<div class="clear"></div>
<?php $this->load->view('inc/footer'); ?>